/*
 * @Date: 2021-09-07 20:09:05
 * @Author: Acckno1
 * @LastEditTime: 2021-09-07 20:29:37
 * @Description: 
 */
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 210;

int n, m, k;
bool g[N][N], st[N];
int nodes[N * 2];

/**
 * @description: 判断哈密顿图
 * @param {int} cnt 节点长度
 * @return {*}
 */
bool check(int cnt) {
    // 首尾不相等 或者 总共节点数 不等于 n + 1
    if (nodes[0] != nodes[cnt - 1] || cnt != n + 1) return false;

    mm(st, false);
    // 每一条边存在
    for (int i = 0; i < cnt - 1; i ++ ) {
        st[nodes[i]] = true;
        if (!g[nodes[i]][nodes[i + 1]])
            return false;
    }

    // 每一个节点都被访问到
    for (int i = 1; i <= n; i ++ ) 
        if (!st[i]) return false;
    return true;
}

inline void solution() {
    cin >> n >> m;
    for (int i = 0; i < m; i ++ ) {
        int a, b;
        cin >> a >> b;
        g[a][b] = g[b][a] = true;
    }
    cin >> k;
    while (k -- ) {
        int cnt;
        cin >> cnt;
        for (int i = 0; i < cnt; i ++ ) cin >> nodes[i];

        if (check(cnt)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}